package com.GreenIce.android.UI;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.GreenIce.android.datastructure.ConfigData;
import com.GreenIce.android.datastructure.ConfigData.WorldInfo;
import com.GreenIce.android.util.ResourceIdentifier;

public class WorldAdapter extends BaseAdapter{

	private Context context;
	private Integer[] world;
	public WorldAdapter(Context c, int worldNum){
		context = c;
		world = new Integer[worldNum*2];
		for(int i=1; i<=worldNum; i++){
			world[i-1] = ResourceIdentifier.getDrawableID("world"+i);
		}
		for(int i=1; i<=worldNum; i++){
			world[i+worldNum-1] = ResourceIdentifier.getDrawableID("worldlocked");
		}
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return world.length/2;
	}

	@Override
	public Object getItem(int pos) {
		// TODO Auto-generated method stub
		return pos;
	}

	@Override
	public long getItemId(int pos) {
		// TODO Auto-generated method stub
		return pos;
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ImageView imgView = new ImageView(context);
		int starNum = ConfigData.getInstance().starNum;
		int worldNum = ConfigData.getInstance().worldNum;
		WorldInfo aWorld = ConfigData.getInstance().worldInfo.get(pos);
		if(starNum >= aWorld.lockStar  ){
			imgView.setImageResource(world[pos]);
		}
		else{
			imgView.setImageResource(world[pos+worldNum]);
		}
		imgView.setScaleType(ImageView.ScaleType.FIT_CENTER);
		imgView.setPadding(30, 0, 30, 0);
		return imgView;
	}
}
